<extend name="Public:main" />
<block name="title">找回密码</block>
<block name="custom_css">
    <link rel="stylesheet" href="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.css">
</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="{:U('Index/index')}">
            <i></i>
        </a>
        <div class="flex1">
            找回密码
        </div>
        <a href="javascript:void(0)">
            <i></i>
        </a>
    </div>
    <div style="height: 0.44rem;"></div>
    <form action="" method="post">
        <div class="login">
            <div>
                <label>手机号</label>
                <input type="text" name="account" placeholder="手机号" onInput ="returnNum(this)" maxlength="11">
            </div>
            <div>
                <label>验证码</label>
                <input type="text" name="code" placeholder="验证码" onInput ="returnNum(this)" >
                <button class="get_yzm" id="getcode" onclick="getnum()">
                    获取验证码
                </button>
            </div>
        </div>
        <div class="login">
            <div>
                <label>新密码</label>
                <input type="password" name="password" placeholder="6-32位数字、字母组合" maxlength="32" minlength="6">
            </div>
        </div>
        <input class="login_btn" type="button" ng-click="sub()" value="确认">
    </form>
</body>
<block name="custom_js">
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.js"></script>
    <script>
        function getnum() {
            var time = 60;
            var t;
            var type=1; //reg

            $("#getcode").attr("disabled", true);
            $.post("{:U('Register/sendCode')}", {account: $("input[name='account']").val(), type: 2}, function (data) {
                if (data.code == 0) {
                    $("#getcode").html(time + "s");
                    t = setInterval(countdown, 1000);
                } else {
                    layer.msg(data.msg,{time:1000});
                    $("#getcode").attr("disabled", false);
                }
            });

            function countdown() {
                time = time - 1;
                $("#getcode").html(time + "s");
                $("#getcode").attr("disabled", true);
                if (time == 0) {
                    $("#getcode").html("获取验证码");
                    clearInterval(t);
                    $("#getcode").attr("disabled", false);
                }
            }
        }


        function returnNum(_this) {
            _this.value = _this.value.replace(/[^0-9]/g, '');
        }
    </script>
    <script>
        var app = getApp('myApp', []);
        app.controller('Ctrl', function ($scope, $http) {
            $scope.sub=function () {
                $http({
                    method:'POST',
                    data:{
                        "account" : $("input[name='account']").val(),
                        "code" : $("input[name='code']").val(),
                        "password" : $("input[name='password']").val(),
                    },
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                    transformRequest: function(obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/Register/forgetpasswd"
                }).then(function successCallback(response) {
                    if(response.data.code==0){
                        layer.msg(response.data.msg);
                        setTimeout(function () {
                            window.location.href="/index.php/Home/Login/login"
                        },1500)
                    }else {
                        layer.msg(response.data.msg)
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });
            }
        });
    </script>
</block>
</block>